package com.px.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.px.dal.AdminMapper;
import com.px.model.AdminInfo;
import com.px.model.getData;
import com.px.unit.Response;

//把当前类注解为控制器
@Controller
public class AdminController {
	// 实例化我们的数据操作类
	AdminMapper admin_mapper = new AdminMapper();

	/**
	 * 
	 * 登录请求方法
	 * 前端交互为vuecli框架
	 * */
	@ResponseBody
	@CrossOrigin
	@RequestMapping(value = "/validateAdminLogin", method = RequestMethod.POST, produces = "application/json; utf-8")
	public Response validateAdminLogin(@RequestBody AdminInfo user) {
		AdminInfo adminInfo = admin_mapper.validateAdminLogin(user);
		getData mydata = new getData();
		mydata.setCurrentAdminInfo(adminInfo);
		if (adminInfo != null) {
			// 登录成功
			return new Response(200, "登录成功", mydata);
		} else {
			// 登录失败
			return new Response(403, "登录失败");
		}
	}

}
